home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 1311 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  928 b 

  1. Path: info.uah.edu!oreo!gbacon
  2. From: gbacon@oreo (Greg Bacon)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Help a fellow C programer
  5. Date: 13 Jan 1996 01:29:17 GMT
  6. Organization: The University of Alabama in Huntsville
  7. Message-ID: <4d71td$88a@info.uah.edu>
  8. References: <4d3t4q$ea6@klein.delphi.com>
  9. NNTP-Posting-Host: oreo.aspire.cs.uah.edu
  10. X-Newsreader: TIN [version 1.2 PL2]
  11.  
  12. Diane Barker (Barker@mci.newscorp.com) wrote:
  13. : Can any one tell me the C function/statment that is equal to the math 
  14. : function ! (factorial).
  15.  
  16. : Email me at: BARKER@MCI.NEWSCORP.COM  if you can help
  17.  
  18. : Mike Barker
  19.  
  20. int factorial(unsigned int a)
  21. {
  22.    if ((a == 0) || (a == 1))
  23.       return 1;
  24.    else
  25.       return a * factorial(a-1);
  26. }
  27.  
  28. That's a recursive version.  a is unsigned since the factorial operation
  29. is only defined over [0, \infinity)
  30.  
  31. Greg
  32. --
  33. Greg Bacon <gbacon@cs.uah.edu>
  34. University of Alabama in Huntsville
  35. CS Department Systems Support Team
  36.